"""
    @Author  ：思念 
    @File    ：1.批量修改文件夹下的文件名称.py
    @Date    ：2025/3/21 9:50 
"""
import os
from concurrent.futures import ThreadPoolExecutor


def rename_file(file_path, new_name):
    try:
        dir_name = os.path.dirname(file_path)
        file_ext = os.path.splitext(file_path)[1]
        new_file_path = os.path.join(dir_name, new_name + file_ext)
        os.rename(file_path, new_file_path)
        print(f"Renamed {file_path} to {new_file_path}")
    except Exception as e:
        print(f"Error renaming {file_path}: {e}")


def batch_rename_files(folder_path):
    if not os.path.isdir(folder_path):
        print("The provided path is not a valid directory.")
        return
    file_paths = []
    for root, _, files in os.walk(folder_path):
        for file in files:
            file_paths.append(os.path.join(root, file))

    # 只处理前 400 个文件
    file_paths = file_paths[:400]
    base_num = 17300000001
    with ThreadPoolExecutor() as executor:
        for i, file_path in enumerate(file_paths, start=1):
            new_num = base_num + i - 1
            new_name = f"{i}_{new_num}"
            executor.submit(rename_file, file_path, new_name)


if __name__ == "__main__":
    folder_path = 'your_folder_path'  # 请替换为实际的文件夹路径
    batch_rename_files(folder_path)
